package com.seari.groovyrunner.main;

import com.seari.groovyrunner.bean.GroovyTask;
import com.seari.groovyrunner.service.GroovyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Component
@Order(value = 1)
public class StartUpClass implements ApplicationRunner {
	//监控状态
	public static ConcurrentHashMap<String, GroovyTask> serviceMapping = new ConcurrentHashMap<>();

	@Autowired
	public GroovyService groovyService;

	@Override
	public void run(ApplicationArguments arg0){
		init();
	}
	
	public void init() {
		try {
			List<GroovyTask> allTaskList = groovyService.getAllTaskList();
			for (GroovyTask task :
					allTaskList) {
				StartUpClass.serviceMapping.put(task.getGservice(), task);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
